import java.util.Scanner;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Manager extends User {
    public Manager(String id, String username, String password, String phone) {
        super(id, username, password, phone, "manager");
    }
    
    public void manageMovies(Scanner scanner) {
        while (true) {
            System.out.println("\n--- 影片管理 ---");
            System.out.println("1. 列出所有影片");
            System.out.println("2. 添加影片");
            System.out.println("3. 删除影片");
            System.out.println("4. 修改影片");
            System.out.println("5. 查询影片");
            System.out.println("0. 返回上一级");
            System.out.print("请选择: ");
            String choice = scanner.nextLine();
            switch (choice) {
                case "1": 
                    Movie.listAllMovies(); 
                    break;
                case "2": 
                    Movie.addMovie(scanner); 
                    // 记录日志
                    String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
                    LogEntry.addLog(new LogEntry(time, "影片管理", this.getUsername(), "添加影片"));
                    break;
                case "3": 
                    Movie.deleteMovie(scanner); 
                    // 记录日志
                    time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
                    LogEntry.addLog(new LogEntry(time, "影片管理", this.getUsername(), "删除影片"));
                    break;
                case "4": 
                    Movie.modifyMovie(scanner); 
                    // 记录日志
                    time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
                    LogEntry.addLog(new LogEntry(time, "影片管理", this.getUsername(), "修改影片"));
                    break;
                case "5": 
                    Movie.queryMovie(scanner); 
                    break;
                case "0": return;
                default: System.out.println("无效选择，请重试。");
            }
        }
    }
    
    public void manageSchedules(Scanner scanner) {
        while (true) {
            System.out.println("\n--- 排片管理 ---");
            System.out.println("1. 列出所有场次");
            System.out.println("2. 增加场次");
            System.out.println("3. 删除场次");
            System.out.println("4. 修改场次");
            System.out.println("5. 查询场次座位");
            System.out.println("6. 自动排片");
            System.out.println("0. 返回上一级");
            System.out.print("请选择: ");
            String choice = scanner.nextLine();
            switch (choice) {
                case "1": 
                    Schedule.listAllSchedules(); 
                    break;
                case "2": 
                    Schedule.addSchedule(scanner); 
                    // 记录日志
                    String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
                    LogEntry.addLog(new LogEntry(time, "排片管理", this.getUsername(), "添加场次"));
                    break;
                case "3": 
                    Schedule.deleteSchedule(scanner); 
                    // 记录日志
                    time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
                    LogEntry.addLog(new LogEntry(time, "排片管理", this.getUsername(), "删除场次"));
                    break;
                case "4": 
                    Schedule.modifySchedule(scanner); 
                    // 记录日志
                    time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
                    LogEntry.addLog(new LogEntry(time, "排片管理", this.getUsername(), "修改场次"));
                    break;
                case "5": 
                    Schedule.queryScheduleSeats(scanner); 
                    break;
                case "6": 
                    Schedule.autoSchedule(); 
                    break;
                case "0": return;
                default: System.out.println("无效选择，请重试。");
            }
        }
    }
    
    public void viewSales(SalesService salesService, Scanner scanner) {
        while (true) {
            System.out.println("\n--- 销售统计 ---");
            System.out.println("1. 查看当日销售数据");
            System.out.println("2. 查看当周销售数据");
            System.out.println("3. 查看当月销售数据");
            System.out.println("0. 返回上一级");
            System.out.print("请选择: ");
            String choice = scanner.nextLine();
            switch (choice) {
                case "1": 
                    salesService.showTodaySales(); 
                    break;
                case "2": 
                    salesService.showWeekSales(); 
                    break;
                case "3": 
                    salesService.showMonthSales(); 
                    break;
                case "0": return;
                default: System.out.println("无效选择，请重试。");
            }
        }
    }
} 